package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"sync"
)

var (
	Db   *gorm.DB
	err  error
	once sync.Once
)

func InitMySQL() {
	dsn := "root:root@tcp(127.0.0.1:3306)/day4?charset=utf8mb4&parseTime=True&loc=Local"
	once.Do(func() {
		Db, err = gorm.Open(mysql.Open(dsn))
		if err != nil {
			fmt.Println("数据库连接失败")
			return
		}
	})
	Db.AutoMigrate(new(Goods))
}
